package net.zoneland.knowledge.dao;

import java.util.List;
import net.zoneland.knowledge.model.SubjectLevel;
import net.zoneland.knowledge.model.SubjectLevelExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface SubjectLevelMapper {
    @SelectProvider(type=SubjectLevelSqlProvider.class, method="countByExample")
    long countByExample(SubjectLevelExample example);

    @Delete({
        "delete from AITK_SUBJECT_LEVEL",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @Insert({
        "insert into AITK_SUBJECT_LEVEL (ID, CATEGORY, ",
        "SUBJECT_LEVEL, SUBJECT_NAME, ",
        "PARENT_ID, PARENT_SUBJECT_NAME, ",
        "DELETED, ORDERS)",
        "values (#{id,jdbcType=VARCHAR}, #{category,jdbcType=VARCHAR}, ",
        "#{subjectLevel,jdbcType=DECIMAL}, #{subjectName,jdbcType=VARCHAR}, ",
        "#{parentId,jdbcType=VARCHAR}, #{parentSubjectName,jdbcType=VARCHAR}, ",
        "#{deleted,jdbcType=DECIMAL}, #{orders,jdbcType=DECIMAL})"
    })
    int insert(SubjectLevel record);

    @InsertProvider(type=SubjectLevelSqlProvider.class, method="insertSelective")
    int insertSelective(SubjectLevel record);

    @SelectProvider(type=SubjectLevelSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="ID", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="CATEGORY", property="category", jdbcType=JdbcType.VARCHAR),
        @Result(column="SUBJECT_LEVEL", property="subjectLevel", jdbcType=JdbcType.DECIMAL),
        @Result(column="SUBJECT_NAME", property="subjectName", jdbcType=JdbcType.VARCHAR),
        @Result(column="PARENT_ID", property="parentId", jdbcType=JdbcType.VARCHAR),
        @Result(column="PARENT_SUBJECT_NAME", property="parentSubjectName", jdbcType=JdbcType.VARCHAR),
        @Result(column="DELETED", property="deleted", jdbcType=JdbcType.DECIMAL),
        @Result(column="ORDERS", property="orders", jdbcType=JdbcType.DECIMAL)
    })
    List<SubjectLevel> selectByExample(SubjectLevelExample example);

    @Select({
        "select",
        "ID, CATEGORY, SUBJECT_LEVEL, SUBJECT_NAME, PARENT_ID, PARENT_SUBJECT_NAME, DELETED, ",
        "ORDERS",
        "from AITK_SUBJECT_LEVEL",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="ID", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="CATEGORY", property="category", jdbcType=JdbcType.VARCHAR),
        @Result(column="SUBJECT_LEVEL", property="subjectLevel", jdbcType=JdbcType.DECIMAL),
        @Result(column="SUBJECT_NAME", property="subjectName", jdbcType=JdbcType.VARCHAR),
        @Result(column="PARENT_ID", property="parentId", jdbcType=JdbcType.VARCHAR),
        @Result(column="PARENT_SUBJECT_NAME", property="parentSubjectName", jdbcType=JdbcType.VARCHAR),
        @Result(column="DELETED", property="deleted", jdbcType=JdbcType.DECIMAL),
        @Result(column="ORDERS", property="orders", jdbcType=JdbcType.DECIMAL)
    })
    SubjectLevel selectByPrimaryKey(String id);

    @UpdateProvider(type=SubjectLevelSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SubjectLevel record);

    @Update({
        "update AITK_SUBJECT_LEVEL",
        "set CATEGORY = #{category,jdbcType=VARCHAR},",
          "SUBJECT_LEVEL = #{subjectLevel,jdbcType=DECIMAL},",
          "SUBJECT_NAME = #{subjectName,jdbcType=VARCHAR},",
          "PARENT_ID = #{parentId,jdbcType=VARCHAR},",
          "PARENT_SUBJECT_NAME = #{parentSubjectName,jdbcType=VARCHAR},",
          "DELETED = #{deleted,jdbcType=DECIMAL},",
          "ORDERS = #{orders,jdbcType=DECIMAL}",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(SubjectLevel record);


    @Select({
            "SELECT ",
            "ID, CATEGORY, SUBJECT_LEVEL, SUBJECT_NAME, PARENT_ID, PARENT_SUBJECT_NAME, DELETED, ORDERS ",
            "FROM AITK_SUBJECT_LEVEL ",
            "WHERE DELETED = 0 AND CATEGORY= #{category,jdbcType=VARCHAR} AND PARENT_SUBJECT_NAME= #{subjectName,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="ID", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="CATEGORY", property="category", jdbcType=JdbcType.VARCHAR),
            @Result(column="SUBJECT_LEVEL", property="subjectLevel", jdbcType=JdbcType.DECIMAL),
            @Result(column="SUBJECT_NAME", property="subjectName", jdbcType=JdbcType.VARCHAR),
            @Result(column="PARENT_ID", property="parentId", jdbcType=JdbcType.VARCHAR),
            @Result(column="PARENT_SUBJECT_NAME", property="parentSubjectName", jdbcType=JdbcType.VARCHAR),
            @Result(column="DELETED", property="deleted", jdbcType=JdbcType.DECIMAL),
            @Result(column="ORDERS", property="orders", jdbcType=JdbcType.DECIMAL)
    })
    List<SubjectLevel> selectByLevel(@Param("category") final String category, @Param("subjectName") final String subjectName);
}